<?php
/**
 * /depot/library/models/Object/PageInfo.php
 * @author qqinxl
 * 2008/03/31
 * 
 * @category  
 * @package  
 * @copyright  Copyright (c) {}
 */
class Object_PageInfo {
	
	private $module;
	
	private $moduleUrl;
	
	private $action;
	
	private $controller;
	
	private $counts;
	
	private $page = 1;
	
	private $ispagelist = false;
	
	private $id;
	
	private $orderby;
	
	private $ordersort;
	
	private $pagenumber;
	
	private $linklist;
	
	private $totalnumber;
	
	private $limit = null;
	
	private $offset = null;
	
	private $url;
	
	private $baseUrl;
	
	private $pageUrl;
	
	private $currentUrl;
	
	private $currentUrlWithPageList;
	
	private $currentModuleUrl;
	
	private $ajaxid;
	
	/**
	 * @return unknown
	 */
	public function getCurrentModuleUrl() {
		return $this->currentModuleUrl;
	}
	
	/**
	 * @param unknown_type $currentModuleUrl
	 */
	public function setCurrentModuleUrl($currentModuleUrl) {
		$this->currentModuleUrl = $currentModuleUrl;
	}
	/**
	 * @return unknown
	 */
	public function isPagelist() {
		return $this->ispagelist;
	}
	
	/**
	 * @param unknown_type $ispagelist
	 */
	public function setIspagelist($ispagelist) {
		$this->ispagelist = $ispagelist;
	}
	/**
	 * @return unknown
	 */
	public function getCurrentUrlWithPageList() {
		return $this->currentUrlWithPageList;
	}
	
	/**
	 * @param unknown_type $currentUrlWithPageList
	 */
	public function setCurrentUrlWithPageList($currentUrlWithPageList) {
		$this->currentUrlWithPageList = $currentUrlWithPageList;
	}
	/**
	 * @return unknown
	 */
	public function getAjaxid() {
		return $this->ajaxid;
	}
	
	/**
	 * @param unknown_type $ajaxid
	 */
	public function setAjaxid($ajaxid) {
		$this->ajaxid = $ajaxid;
	}
	/**
	 * @return unknown
	 */
	public function getCurrentUrl() {
		return $this->currentUrl;
	}
	
	/**
	 * @param unknown_type $currentUrl
	 */
	public function setCurrentUrl($currentUrl) {
		$this->currentUrl = $currentUrl;
	}
	public function getBaseUrl() {
		return $this->baseUrl;
	}
	
	
	public function getLimit() {
		return $this->limit;
	}
	
	
	public function getLinklist() {
		return $this->linklist;
	}
	

	public function getOffset() {
		return $this->offset;
	}
	
	
	public function getPagenumber() {
		return $this->pagenumber;
	}
	

	public function getPageUrl() {
		return $this->pageUrl;
	}
	

	public function getTotalnumber() {
		return $this->totalnumber;
	}
	

	public function getUrl() {
		return $this->url;
	}
	

	public function setBaseUrl($baseUrl) {
		$this->baseUrl = $baseUrl;
	}
	
	
	public function setLimit($limit) {
		$this->limit = $limit;
	}
	
	
	public function setLinklist($linklist) {
		$this->linklist = $linklist;
	}
	
	
	public function setOffset($offset) {
		$this->offset = $offset;
	}
	
	
	public function setPagenumber($pagenumber) {
		$this->pagenumber = $pagenumber;
	}
	
	
	public function setPageUrl($pageUrl) {
		$this->pageUrl = $pageUrl;
	}
	
	
	public function setTotalnumber($totalnumber) {
		$this->totalnumber = $totalnumber;
	}
	
	
	public function setUrl($url) {
		$this->url = $url;
	}
	public function getModuleUrl() {
		return $this->moduleUrl;
	}
	
	public function setModuleUrl($moduleUrl) {
		$this->moduleUrl = $moduleUrl;
	}
	public function getAction() {
		return $this->action;
	}
	
	public function getController() {
		return $this->controller;
	}
	
	public function getCounts() {
		return $this->counts;
	}
	
	public function getId() {
		return $this->id;
	}
	
	public function getModule() {
		return $this->module;
	}
	
	public function isAdminModule(){
		return (strtolower($this->module) == 'admin');
	}
	public function getOrderby() {
		return $this->orderby;
	}
	
	public function getOrdersort() {
		return $this->ordersort;
	}
	
	public function getPage() {
		return $this->page;
	}
	
	public function setAction($action) {
		$this->action = $action;
	}
	
	public function setController($controller) {
		$this->controller = $controller;
	}
	
	public function setCounts($counts) {
		$this->counts = $counts;
	}
	
	public function setId($id) {
		$this->id = $id;
	}
	
	public function setModule($module) {
		$this->module = $module;
	}
	
	public function setOrderby($orderby) {
		$this->orderby = $orderby;
	}
	
	public function setOrdersort($ordersort) {
		$this->ordersort = $ordersort;
	}
	
	public function setPage($page) {
		$this->page = $page;
	}
	
	public function init($params,$baseUrl) {
		if(!isset ( $params ['page'])){
			$this->setIspagelist(false);
		}else{
			$page = (int)(trim($params ['page']));
			if($page > 0){
				$this->setIspagelist(true);
			}else{
				$this->setIspagelist(false);
			}
		}
		
		$this->setBaseUrl($baseUrl);
		$this->setModule ( $params ['module'] );
		if (strtolower ( $this->getModule () ) == 'default') {
			$this->setModuleUrl ( '' );
		} else {
			$this->setModuleUrl ( $this->getModule () . '/' );
		}		
		$this->setAction ( $params ['action'] );
		$this->setController($params ['controller'] );
		
		$this->setId ( isset ( $params ['id'] ) ? $params ['id'] : null );
		$this->setCounts ( isset ( $params ['counts'] ) ? $params ['counts'] : null );
		$this->setPage ( isset ( $params ['page'] ) ? $params ['page'] : 1 );		
		$this->setOrderby ( isset ( $params ['orderby'] ) ? $params ['orderby'] : null );
		$this->setOrdersort ( isset ( $params ['ordersort'] ) ? $params ['ordersort'] : null );
		$this->setAjaxid(isset ( $params ['ajaxid'] ) ? $params ['ajaxid'] : null );
		$orderby = $this->getOrderby ();
		$ordersort = $this->getOrdersort ();
		if(empty($orderby) ){
			$this->setOrdersort (null);
		}elseif (! empty ( $orderby ) and empty ( $ordersort )) {
			$this->setOrdersort ( 'DESC' );
		}
		$this->setCurrentUrl($this->getBaseUrl().'/'.$this->getModuleUrl().$this->getController().'/'.$this->getAction());
		$this->setCurrentModuleUrl($this->getBaseUrl().'/'.$this->getModuleUrl());		
		$this->setCurrentUrlWithPageList($this->getBaseUrl().'/'.$this->getModuleUrl().$this->getController().'/'.$this->getAction().'/page/'.$this->getPage());
	}
	
	public function addInfo($pageUrl,$pagenumber = 5, $linklist = 3) {
		$this->setPagenumber($pagenumber);
		$this->setLinklist($linklist);
		$this->setPageUrl($pageUrl);
		
		$_urlString = $this->getPageUrl();
		$counts = $this->getCounts();
		$id = $this->getId();
		$orderby = $this->getOrderby ();
		$ordersort = $this->getOrdersort ();
		$_urlString .= (!empty($counts))?'/counts/' . $counts:'';
		$_urlString .= (!empty($id))?'/id/' . $id:'';
		$_urlString .= (!empty($orderby))?'/orderby/' . $orderby:'';
		$_urlString .= (!empty($ordersort))?'/ordersort/' . $ordersort:'';		
		$this->setUrl($_urlString);
		
		$this->setTotalnumber($counts);			
		$totalpage = ( int ) ($this->getTotalnumber() / $this->getPagenumber());
		if ($totalpage * $this->getPagenumber() < $this->getTotalnumber()) {
			$totalpage ++;
		}
		$this->setTotalnumber($totalpage);		
		$this->setLimit($this->getPagenumber());		
		$offset = $this->getPagenumber() *($this->getPage()-1);
		if($offset<0){
			$offset = 0;
		}
		$this->setOffset($offset);
	}
	
	public function isAjaxHttpRequest(){
		return !empty($this->ajaxid);
	}
	public function isAdminController(){
		return ($this->module == 'admin');
	}
	public function isDefaultController(){
		return ($this->module == 'default');
	}

}